<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<div class="card">
	<div class="card-header">
		<?php echo lang('top_thread');?>
	</div>
	<div class="card-body ajax-body">
		<form action="<?php echo $url_path.url('operate-sticky');?>" method="post" id="mode_sticky_form">
			<?php echo form_hidden('safe_token', $safe_token);?>
			<div class="form-group d-flex justify-content-center">
				<span class="mr-2">
					<?php echo lang('total');?>
                </span>
				<span>
					<span class="total font-weight-bold text-danger"></span>
                    <?php echo lang('piece');?>
				</span>
			</div>
			<div class="form-group row text-center">
				<div class="col-12">
					<label class="custom-input custom-radio mr-2"><input class="mr-2" type="radio" name="sticky" value="0" />
                        <?php echo lang('top_0');?>
                    </label>
					<label class="custom-input custom-radio mr-2">
                        <input class="mr-2" type="radio" name="sticky" value="1" />
                        <?php echo lang('top_1');?>
                    </label>
					<?php if ($fup) { ?>
					<label class="custom-input custom-radio mr-2">
                        <input class="mr-2" type="radio" name="sticky" value="2" />
                        <?php echo lang('top_2');?>
                    </label>
					<?php } ?>
					<label class="custom-input custom-radio mr-2"><input type="radio" name="sticky" value="3" />
                        <?php echo lang('top_3');?>
                    </label>
				</div>
			</div>
			<div class="form-group d-flex justify-content-center">
				<button type="submit" class="btn btn-primary mr-2" data-loading-text="<?php echo lang('submiting');?>...">
					<?php echo lang('confirm');?>
				</button>
				<button type="button" class="btn btn-secondary" data-dismiss="modal">
					<?php echo lang('close');?>
				</button>
			</div>
		</form>
	</div>
</div>

<?php include _include(APP_PATH.($backstage?'admin/':'').'view/htm/footer.inc.htm');?>

<script ajax-eval="true">
var args = args || {jmodal: null, callback: null, arg: null};
var jmodal = args.jmodal;
var callback = args.callback;
var arg = args.arg;
var jthreadlist = $(arg); /*.threadlist*/
var tidarr = jthreadlist.find('input[name="modtid"]').checked();

var jform = $('#mode_sticky_form');
var jsubmit = jform.find('button[type="submit"]');
var jsticky = jform.find('input[name="sticky"]');
var jtotal = jform.find('span.total');
jtotal.text(tidarr.length);

jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serializeObject();
	postdata.tidarr = tidarr;
	postdata.sticky = jsticky.checked();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.button(message);
			setTimeout(function() {
				if(jmodal) jmodal.modal('dispose');
				if(callback) callback(message);
				window.location.reload();
			}, 1000);
		} else {
			alert(message);
			jsubmit.button('reset');
		}
	});
	return false;
});
</script>